<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
	<head>
		<base href="<%=basePath%>">
		<title>insert title</title>
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">    
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<!--
			<link rel="stylesheet" type="text/css" href="styles.css">
		-->
		<link rel="stylesheet" type="text/css" href="<%=basePath %>scripts/static/h-ui/css/H-ui.min.css" />
		<link rel="stylesheet" type="text/css" href="<%=basePath %>scripts/static/h-ui.admin/css/H-ui.admin.css" />
		<link rel="stylesheet" type="text/css" href="<%=basePath %>scripts/lib/Hui-iconfont/1.0.7/iconfont.css" />
		<link rel="stylesheet" type="text/css" href="<%=basePath %>scripts/lib/icheck/icheck.css" />
		<link rel="stylesheet" type="text/css" href="<%=basePath %>scripts/static/h-ui.admin/skin/default/skin.css" id="skin" />
		<link rel="stylesheet" type="text/css" href="<%=basePath %>scripts/static/h-ui.admin/css/style.css" />
		<style type="text/css">
			.ui-hidden{display: none;}
			.ui-show{display:block;}
		</style>
		
	</head>
	<body>
		<div id="main-panel" class="page-container">
			
			<form class="form form-horizontal">
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>课程编号：</label>
					<div class="formControls col-xs-8 col-sm-4">
						<input id="courceNo" type="text" class="input-text" readonly="readonly"/>
					</div>
					<div class="formControls col-xs-8 col-sm-3">
						<input id="courceName" type="text" class="input-text" readonly="readonly"/>
					</div>
					<div class="formControls col-xs-8 col-sm-2">
						<input type="button" class="btn" onclick="courcePanel()" value="搜索课程"/>
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>教师编号：</label>
					<div class="formControls col-xs-8 col-sm-4">
						<input id="teacherNo" type="text" class="input-text" readonly="readonly"/>
					</div>
					<div class="formControls col-xs-8 col-sm-3">
						<input id="teacherName" type="text" class="input-text" readonly="readonly"/>
					</div>
					<div class="formControls col-xs-8 col-sm-2">
						<input type="button" class="btn" onclick="teacherPanel()" value="搜索教师"/>
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>班级编号：</label>
					<div class="formControls col-xs-8 col-sm-4">
						<input id="sclassNo" type="text" class="input-text" readonly="readonly"/>
					</div>
					<div class="formControls col-xs-8 col-sm-3">
						<input id="sclassName" type="text" class="input-text" readonly="readonly"/>
					</div>
					<div class="formControls col-xs-8 col-sm-2">
						<input type="button" class="btn" onclick="sclassPanel()" value="搜索班级"/>
					</div>
				</div>
				
				<div class="row cl">
					<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
						<button onClick="cource_employee()" class="btn btn-primary radius" type="button"><i class="Hui-iconfont">&#xe632;</i> 提交</button>
						<button onClick="layer_close()" class="btn btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
					</div>
				</div>
			</form>
		</div>
		<div id="cource" class="ui-hidden page-container">
			<div class="row cl">
				<div class="formControls col-xs-8 col-sm-7">
					<input id="courceName" type="text" placeholder="请输入课程名称关键字" class="input-text"/>
				</div>
				<button name="" id="" class="btn btn-success" type="button" onclick="searchCource()"><i class="Hui-iconfont">&#xe665;</i> 搜课程</button>
			</div>
			<br/>
			<table class="table table-border table-bordered table-bg table-hover table-sort">
			<thead>
				<tr class="text-c">
					<th width="100">课程编号</th>
					<th width="120">课程名称</th>
					<th width="80">学分</th>
					<th width="80">操作</th>
				</tr>
			</thead>
			<tbody id="data">
				
			</tbody>
			</table>
		</div>
		<div id="sclass" class="ui-hidden page-container form form-horizontal">
				<div class="row cl">
					<div class="formControls col-xs-8 col-sm-6">
						<select id="college-data" class="input-text">
							<option>请选择学院</option>
						</select>
					</div>
					<div class="formControls col-xs-8 col-sm-6">
						<select id="major-data" class="input-text">
							<option>请选择专业</option>
						</select>
					</div>
				</div>
				<div class="row cl">
					<div class="formControls col-xs-8 col-sm-6">
						<select id="grade-data" class="input-text">
							<option value="all">请选择年级</option>
						</select>
					</div>
					<div class="formControls col-xs-8 col-sm-3">
						<input type="text" class="input-text" placeholder="请输入班级名关键字" id="sclassName">
					</div>
					<div class="formControls col-xs-8 col-sm-3">
						<button name="" id="" class="btn btn-success" type="button" onclick="searchSclass()" ><i class="Hui-iconfont">&#xe665;</i> 搜班级</button>
					</div>
				</div>
			<br/>
			<table class="table table-border table-bordered table-bg table-hover table-sort">
			<thead>
				<tr class="text-c">
					<th width="80">班级编号</th>
					<th width="80">班级名称</th>
					<th width="80">年级</th>
					<th width="80">专业</th>
					<th width="80">学院</th>
					<th width="80">操作</th>
				</tr>
			</thead>
			<tbody id="data">
				
			</tbody>
			</table>
		</div>
		<div id="teacher" class="ui-hidden page-container">
			<div class="row cl">
					<div class="formControls col-xs-8 col-sm-6">
						<select id="college-data" class="input-text">
							<option>请选择学院</option>
						</select>
					</div>
					<div class="formControls col-xs-8 col-sm-3">
						<input type="text" class="input-text" placeholder="请输入教师名字" id="teacherName">
					</div>
					<div class="formControls col-xs-8 col-sm-3">
						<button name="" id="" class="btn btn-success" type="button" onclick="searchTeacher()"><i class="Hui-iconfont">&#xe665;</i> 搜教师</button>
					</div>
				</div>
			<br/>
			<table class="table table-border table-bordered table-bg table-hover table-sort">
			<thead>
				<tr class="text-c">
					<th width="80">教师编号</th>
					<th width="80">教师名称</th>
					<th width="120">学院</th>
					<th width="80">操作</th>
				</tr>
			</thead>
			<tbody id="data">
				
			</tbody>
			</table>
		</div>
	</body>
		<script type="text/javascript" src="<%=basePath %>scripts/jquery-1.9.1.js"></script>
		<script type="text/javascript" src="<%=basePath %>scripts/lib/layer/2.1/layer.js"></script>
		<script type="text/javascript">
			window.onload = function(){
				$.ajax({
					url:'<%=basePath%>courceEmployee/json/loadCollege',
					type:'get',
					dataType:'json',
					success:function(data){
						var html="<option value='all'>请选择学院</option>";
						$.each(data,function(i,val){
							html+="<option value='"+val.collegeNo+"'>"+val.coolegeName+"</option>";
						});
						$("#sclass #college-data").html(html);
						$("#teacher #college-data").html(html);
						//alert(html);
					},
					error:function(){
						layer.msg("ajax error");
					}
				});
			};
			$(function(){
				$("#sclass #college-data").change(function(){
					var collegeNo = $(this).val();
					if(collegeNo!="all"){
						var html = "<option value='all'>请选择专业</option>";
						$.ajax({
							url:'<%=basePath%>courceEmployee/json/loadMajor/'+collegeNo,
							type:'get',
							dataType:'json',
							success:function(data){
								$.each(data,function(i,val){
									html+="<option value='"+val.majorNo+"'>"+val.majorName+"</option>";
								});
								$("#sclass #major-data").html(html);
							},
							error:function(){
								layer.msg('ajax error');
							}
						});
					}
				});
				$("#sclass #major-data").change(function(){
					var majorNo = $(this).val();
					if(majorNo!="all"){
						var html = "<option value='all'>请选择年级</option>";
						$.ajax({
							url:'<%=basePath%>courceEmployee/json/loadGrade/'+majorNo,
							type:'get',
							dataType:'json',
							success:function(data){
								$.each(data,function(i,val){
									html+="<option value='"+val.gradeNo+"'>"+val.gradeName+"</option>";
								});
								$("#sclass #grade-data").html(html);
							},
							error:function(){
								layer.msg('ajax error');
							}
						});
					}
				});
				$("#sclass #data").on('click','tr td #addSclass',function(){
					//alert('hello');
					var sclassNo = $(this).parents("tr").children("#sclassNo").text();
					var sclassName = $(this).parents("tr").children("#sclassName").text();
					$("#main-panel #sclassNo").attr("value",sclassNo);
					$("#main-panel #sclassName").attr("value",sclassName);
					layer.closeAll();
				});
				$("#cource #data").on('click','tr td #addCource',function(){
					var courceNo = $(this).parents("tr").children("#courceNo").text();
					var courceName = $(this).parents("tr").children("#courceName").text();
					$("#main-panel #courceNo").attr("value",courceNo);
					$("#main-panel #courceName").attr("value",courceName);
					layer.closeAll();
				});
				$("#teacher #data").on('click','tr td #addTeacher',function(){
					var teacherNo = $(this).parents("tr").children("#teacherNo").text();
					var teacherName = $(this).parents("tr").children("#teacherName").text();
					$("#main-panel #teacherNo").attr("value",teacherNo);
					$("#main-panel #teacherName").attr("value",teacherName);
					layer.closeAll();
				});
			});
			
			/*班级搜索*/
			function searchSclass(){
				var gradeNo = $("#sclass #grade-data").val();
				var sclassName=$("#sclass #sclassName").val();
				var jsonUrl = "<%=basePath%>courceEmployee/json/searchSclass";
				
				var inputData;//存放参数
				if(gradeNo!="all" && sclassName!=""){//判断参数个数和值
					inputData = {"gradeNo":gradeNo,"sclassName":sclassName};
				}else if(gradeNo == "all" && sclassName!=""){
					inputData = {"sclassName":sclassName};
				}else if(gradeNo !="all" && sclassName==""){
					inputData = {"gradeNo":gradeNo};
				}else{
					inputData = {};
				}
				$.ajax({
					url:jsonUrl,
					type:'get',
					dataType:'json',
					data:inputData,
					success:function(data){
						var html = "";
						if(data==""){
							html+="<tr class='text-c'><td colspan='8'>没有数据</td></tr>";
							$("#sclass #data").html(html);
						}else{
							$.each(data,function(i,val){
								html+="<tr class='text-c'>"+
								  	  "<td id='sclassNo'>"+val.classNo+"</td>"+
								  	  "<td id='sclassName'>"+val.className+"</td>"+
								  	  "<td>"+val.grade.gradeName+"</td>"+
								  	  "<td>"+val.grade.major.majorName+"</td>"+
								  	  "<td>"+val.grade.major.college.coolegeName+"</td>"+
								  	  "<td><button id='addSclass' class='btn btn-primary'>添加</button></td>"+
								  	  "</tr>";
							});
							$("#sclass #data").html(html);
						}
					},
					error:function(){
						layer.msg('ajax error');
					}
				});
				
			}
			/*搜索课程*/
			function searchCource(){
				var courceName = $("#cource #courceName").val();
				var jsonUrl = "<%=basePath%>courceEmployee/json/searchCource";
				var inputData;
				if(courceName==""){
					inputData = {};
				}else{
					inputData = {"courceName":courceName}
				}
				$.ajax({
					url:jsonUrl,
					type:'get',
					dataType:'json',
					data:inputData,
					success:function(data){
						var html = "";
						if(data==""){
							html+="<tr class='text-c'><td colspan='8'>没有数据</td></tr>";
							
						}else{
							$.each(data,function(i,val){
								html+="<tr class='text-c'>"+
							  	  "<td id='courceNo'>"+val.courceNo+"</td>"+
							  	  "<td id='courceName'>"+val.courceName+"</td>"+
							  	  "<td>"+val.courceScore+"</td>"+
							  	  "<td><button id='addCource' class='btn btn-primary'>添加</button></td>"+
							  	  "</tr>";
							});
						}
						$("#cource #data").html(html);
					},
					error:function(){
						layer.msg("ajax error");
					}
				});
			}
			/*搜索教师*/
			function searchTeacher(){
				var collegeNo = $("#teacher #college-data").val();
				var teacherName = $("#teacher #teacherName").val();
				var jsonUrl = "<%=basePath%>courceEmployee/json/searchTeacher";
				var inputData;
				if(collegeNo!="all" && teacherName!=""){
					inputData={"collegeNo":collegeNo,"teacherName":teacherName};
				}else if(collegeNo!="all" && teacherName==""){
					inputData={"collegeNo":collegeNo};
				}else if(collegeNo=="all" && teacherName!=""){
					inputData={"teacherName":teacherName};
				}else{
					inputData={};
				}
				$.ajax({
					url:jsonUrl,
					type:'get',
					dataType:'json',
					data:inputData,
					success:function(data){
						var html = "";
						if(data==""){
							html+="<tr class='text-c'><td colspan='8'>没有数据</td></tr>";
							
						}else{
							$.each(data,function(i,val){
								html+="<tr class='text-c'>"+
							  	  "<td id='teacherNo'>"+val.teacherNo+"</td>"+
							  	  "<td id='teacherName'>"+val.teacherName+"</td>"+
							  	  "<td>"+val.college.coolegeName+"</td>"+
							  	  "<td><button id='addTeacher' class='btn btn-primary'>添加</button></td>"+
							  	  "</tr>";
							});
						}
						$("#teacher #data").html(html);
					},
					error:function(){
						layer.msg('ajax error');
					}
				});
			}
			/*提交任免信息*/
			function cource_employee(){
				var courceNo = $("#main-panel #courceNo").val();
				var teacherNo = $("#main-panel #teacherNo").val();
				var sclassNo = $("#main-panel #sclassNo").val();
				var jsonUrl = "<%=basePath%>courceEmployee/addCourceEmployee";
				var inputData = {"courceNo":courceNo,"teacherNo":teacherNo,"sclassNo":sclassNo};
				if(courceNo=="" || teacherNo=="" || sclassNo==""){
					layer.msg('必填字段不能为空，请检查');
				}else{
					$.ajax({
						url:jsonUrl,
						type:'post',
						dataType:'text',
						data:inputData,
						success:function(text){
							layer.msg('添加成功');
							setTimeout(function(){
								window.parent.location.reload();
							}, 1000);
						},
						error:function(){
							layer.msg('添加失败');
						}
					})
				}
			}
			function courcePanel(){
				layer.open({
					type:1,
					title:'课程添加',
					area:['700px','500px'],
					content:$("#cource")
				});
			}
			function teacherPanel(){
				layer.open({
					type:1,
					title:'教师添加',
					area:['700px','500px'],
					content:$("#teacher")
				});
			}
			function sclassPanel(){
				layer.open({
					type:1,
					title:'班级添加',
					area:['700px','500px'],
					content:$("#sclass")
				});
			}
			/*关闭layer窗口*/
			function layer_close(){
				window.parent.layer.closeAll();
			}
		</script>
</html>